// pages/service/index.js
var app = getApp();
var wxb = require('../../utils/wxb.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    color: '',
    orderon:true,
    typeon:true,
    datas:[],
    dataArr:[],
    page:1,
    more:0,
    category_id:0,
    ordermsg:'信息交流',
    orderby:0,
    typemsg:'电商平台',
    type:0,
    setting:[],
  },
  callPhone: function (e) {
    wx.showModal({
      title: '提示',
      content:'请添加客服微信13039675307',
      showCancel:false,
     
    })
  },
  showDet(e){
 console.log(e.currentTarget.dataset.ite.img)
    const data = {
      goodAmount :e.currentTarget.dataset.ite.goodAmount,
      goodDisc:e.currentTarget.dataset.ite.goodDisc,
      goodName:e.currentTarget.dataset.ite.goodName,
      goodPrice:e.currentTarget.dataset.ite.goodPrice,
      goodType:e.currentTarget.dataset.ite.goodType,
      id:e.currentTarget.dataset.ite.id,
      img:e.currentTarget.dataset.ite.img,
      phone:e.currentTarget.dataset.ite.phone
    }
    wx.navigateTo({
      url: './goodDetail/goodDetail',
      success(res){
        res.eventChannel.emit('data1',data)
      }
      
    })
  },
  onShow: function () {
    wxb.that = this;
    wxb.style();
    let that1=this;
    if(that1.data.dataArr==''){

      var now = new Date();
      var beginTime = now.getSeconds(); 　//获取当前秒数
      console.log(beginTime);


      



    wx.request({
      url: app.globalData.api+'selectGoodsList?goodtype=4',
      
      success(e){
        console.log(e.data.data)
        that1.setData({
          dataArr:e.data.data
        })
      }
    })

    var endT = new Date();
    var endTime = endT.getSeconds(); //获取当前秒数
    console.log(endTime);
      //获取，两者所差秒数，即js代码运行时间。
  var spTime = (endTime - beginTime);
  console.log(spTime);
  }
  

  


  },
  orderonbin:function(){
    var orderon = this.data.orderon == true ? false : true;
    this.setData({
      orderon: orderon,
        typeon:true,
    }); 
  },
  typeonbin: function () {
    var typeon = this.data.typeon == true ? false : true;
    this.setData({
      orderon: true,
      typeon: typeon,
    });
  },
  getDatas: function (e) {
    wx.showLoading({
      title: '加载中...',
    })
    wxb.Post('/api/service.index/getOnnan', {
      openid: wxb.getOpenId(),
      page: wxb.that.data.page,
      category_id: wxb.that.data.category_id,
      orderby: wxb.that.data.orderby,
      type: wxb.that.data.type,
    }, function (data) {
      wx.hideLoading();
      var datas = wxb.that.data.datas;
      for (var val in data.list) {
        datas.push(data.list[val]);
      }
      wxb.that.setData({
        datas: datas,
        more: data.more,
        page: wxb.that.data.page + 1,
      })
    });
  },
  loadMore: function (e) {
    this.getDatas();
  },
  orderby:function(e){
    let that=this;
    console.log(e.target.dataset.orderby);
    // this.setData({
    //   datas:[],
    //   page:1,
    //   orderby: e.target.dataset.orderby,
    //   ordermsg: e.target.dataset.msg,
    //   orderon:true,
    //   typeon:true,
    // });
    // this.getDatas();
    wx.request({
      url: app.globalData.api+'selectGoodsList?goodtype='+e.target.dataset.orderby,
      success(e){
        console.log(e.data.data)
        that.setData({
          dataArr:e.data.data
        })
      }
    })
  },
  typetab: function (e) {
    this.setData({
      datas: [],
      page: 1,
      type: e.target.dataset.type,
      typemsg: e.target.dataset.msg,
      orderon: true,
      typeon: true,
    });
    this.getDatas();
  },
  onLoad: function (e) {
    wxb.that = this;
    wxb.style();
    this.setData({
      category_id: e.category_id,
    });
    wxb.globalData = app.globalData; //正确打开海天应用的方式
  
  }
})